package edu.gdin.ecommerce.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import edu.gdin.ecommerce.dao.CardIssuerDAO;
import edu.gdin.ecommerce.model.CardIssuer;
import edu.gdin.ecommerce.service.ICardIssuerService;
import edu.gdin.ecommerce.util.Pager;

@Service("cardIssuerService")
public class CardIssuerService implements ICardIssuerService{

	private CardIssuerDAO cardIssuerDAO;
	
	public CardIssuerDAO getCardIssuerDAO() {
		return cardIssuerDAO;
	}

	@Resource(name="cardIssuerDAO")
	public void setCardIssuerDAO(CardIssuerDAO cardIssuerDAO) {
		this.cardIssuerDAO = cardIssuerDAO;
	}

//	@Override
	public boolean isExist(String name) {
		return cardIssuerDAO.isExist(CardIssuer.class, "name", name);
	}

//	@Override
	public boolean addCardIssuer(CardIssuer issuer) {
		try{
			cardIssuerDAO.insert(issuer);
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}

//	@Override
	public Pager queryIssuers(CardIssuer is, int cPage) {
		return this.cardIssuerDAO.queryIssuers(is, cPage);
	}
	
	public CardIssuer getIssuerById(Integer id){
		return (CardIssuer) cardIssuerDAO.findByPk(CardIssuer.class, id);
	}

//	@Override
	public void udpateIssuer(CardIssuer issuer) {
		cardIssuerDAO.update(issuer);
	}
	
	/**
	 * 获取所有有效CardIssuer（即status=1）
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<CardIssuer> getAllIssuer() {
		return (List<CardIssuer>) this.cardIssuerDAO.getEntitysByKey(CardIssuer.class, "status", 1);
	}

}
